﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GA.Server.ApiInfo;
using System.Xml;

namespace GA.Server.Api
{
    public class ApiInfoGetKillData : SignedApiCall
    {
        public IEnumerable<ApiKill> Kill;
        public IEnumerable<ApiKill> KilledBy;

        public ApiInfoGetKillData()
        {
        }

        public ApiInfoGetKillData(int clientId, string authorizationText, string sessionId)
            : base(clientId, authorizationText, sessionId)
        {
        }

        public void LoadApi(int characterId, int days)
        {
            LoadSignedApiCall(string.Format("characterId={0}&days={1}", characterId, days));

            XmlNodeList killNodes = XmlDocument.GetElementsByTagName("a:get_character_kill_summaryResult");
            List<ApiKill> kills = new List<ApiKill>();
            foreach (XmlNode killNode in killNodes)
            {
                kills.Add(new ApiKill(killNode.CreateNavigator().ReadSubtree()));
            }
            Kill = kills;

            XmlNodeList killedByNodes = XmlDocument.GetElementsByTagName("a:get_character_kill_summaryResult");
            List<ApiKill> killedBys = new List<ApiKill>();
            foreach (XmlNode killedByNode in killedByNodes)
            {
                killedBys.Add(new ApiKill(killedByNode.CreateNavigator().ReadSubtree()));
            }
            KilledBy = killedBys;
        }

        protected override string ApiCallName
        {
            get { return "GetKillData"; }
        }
    }
}
